import 'package:chat/common/routers/index.dart';
import 'package:chat/pages/Circle/circle/index.dart';
import 'package:chat/pages/chat/chat/index.dart';
import 'package:chat/pages/chat/chatDetail/index.dart';
import 'package:chat/pages/chat/searchChat/index.dart';
import 'package:chat/pages/friend/addFriennd/addFriend/index.dart';
import 'package:chat/pages/friend/friend/index.dart';
import 'package:chat/pages/main/Main/index.dart';
import 'package:chat/pages/person/person/index.dart';
import 'package:chat/pages/splash/index.dart';
import 'package:chat/pages/user/forget/index.dart';
import 'package:chat/pages/user/login/index.dart';
import 'package:chat/pages/user/phoneLogin/index.dart';
import 'package:chat/pages/user/register/index.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class RoutePages {
  // 历史记录
  static List<String> history = [];

  // 观察者
  static RouteObservers observer = RouteObservers();

  // 路由列表
  static List<GetPage> pageList = [
    GetPage(name: RouteNames.splash, page: () => SplashPage()),
    GetPage(name: RouteNames.login, page: () => LoginPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.register, page: () => RegisterPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.forget, page: () => ForgetPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.phoneLogin, page: () => PhoneloginPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.main, page: () => MainPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.chat, page: () => ChatPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.chatdetail, page: () => ChatdetailPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.searchchat, page: () => SearchchatPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.friend, page: () => FriendPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.addfriend, page: () => AddfriendPage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.circle, page: () => CirclePage(), customTransition: SmoothScaleFadeTransition()),
    GetPage(name: RouteNames.person, page: () => PersonPage(), customTransition: SmoothScaleFadeTransition()),
  ];
}

class SmoothScaleFadeTransition extends CustomTransition {
  @override
  Widget buildTransition(
    BuildContext context,
    Curve? curve,
    Alignment? alignment,
    Animation<double> animation,
    Animation<double> secondaryAnimation,
    Widget child,
  ) {
    final anim = CurvedAnimation(parent: animation, curve: Curves.easeOutCubic);
    return FadeTransition(
      opacity: anim,
      child: SlideTransition(
        position: Tween<Offset>(begin: const Offset(0, 0.06), end: Offset.zero).animate(anim),
        child: ScaleTransition(scale: Tween<double>(begin: 0.99, end: 1.0).animate(anim), child: child),
      ),
    );
  }
}
